package com.mabang.medata.client;

import java.util.ArrayList;
import java.util.List;

import org.apache.axis.encoding.XMLType;
import org.apache.log4j.Logger;

import com.mabang.medata.procotol.QuoteProcotol;
import com.mabang.medata.util.XmlUtil;

public class InsuranceWebserviceClient 
{
	private static final Logger logger = Logger.getLogger(InsuranceWebserviceClient.class);
	/**
	 * 投保
	 * @param trade
	 * @throws Exception 
	 * @throws ServiceException
	 */
	public void insure() throws Exception 
	{
		String request_url="http://localhost:8080/medata-server/ws/getquoteno";
		logger.debug("投保调用保险公司URL：" + request_url);
		AxisWebserviceClient axisWebserviceClient = new AxisWebserviceClient(request_url);
		List paramList = new ArrayList<Param>();
		Param param = new Param();
		param.setParamName("quote");
		String xmlStr = QuoteProcotol.quoteNo("B-001001-201412050197");
		param.setParamValue(xmlStr);
		param.setParamType(XMLType.XSD_STRING);
		paramList.add(param);
		String methodName = "getquoteno";
		try 
		{
			logger.debug("投保webservice开始");
			String resultXml = axisWebserviceClient.invoke(methodName, paramList);
			System.out.println("接收XML："+resultXml);
			logger.debug("投保webservice结束");
			XmlUtil xmlUtil = new XmlUtil(resultXml);
			String orderNo = xmlUtil.getSingleElementValue("policy-name");
			System.out.println("投保人："+orderNo);
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	}
}
